import { defineStore } from "pinia"
import axios from 'axios'
import { handleError } from '@/plugins/err-handle'

export const useRecordStore = defineStore("record", {
  state: () => ({
    records: [],
    page: {},
    serial_num: '',
    currentRecord: {}
  }),
  getters: {
    // doubleCount: (state) => state.counter + 2,
  },
  actions: {
    // 列表
    fetchItems(params) {
      if (params.serial_num) {
        this.serial_num = params.serial_num
      }

      return new Promise((resolve, reject) => {
        // 表单数据
        axios.get('/admin/record', { params })
          .then((response) => {
            // console.log('terminal model 2', response) 
            this.records = response.data.data
            this.page = response.data.meta
            resolve(response)
          })
          .catch((err) => {
            handleError(err)
            reject(err)
          })
        })
    },

  },
})